package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysDiscount;
import com.ruoyi.system.service.ISysDiscountService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 折扣记录Controller
 * 
 * @author ruoyi
 * @date 2024-11-21
 */
@RestController
@RequestMapping("/system/discount")
public class SysDiscountController extends BaseController
{
    @Autowired
    private ISysDiscountService sysDiscountService;

    /**
     * 查询折扣记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:discount:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysDiscount sysDiscount)
    {
        startPage();
        List<SysDiscount> list = sysDiscountService.selectSysDiscountList(sysDiscount);
        return getDataTable(list);
    }

    /**
     * 导出折扣记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:discount:export')")
    @Log(title = "折扣记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysDiscount sysDiscount)
    {
        List<SysDiscount> list = sysDiscountService.selectSysDiscountList(sysDiscount);
        ExcelUtil<SysDiscount> util = new ExcelUtil<SysDiscount>(SysDiscount.class);
        util.exportExcel(response, list, "折扣记录数据");
    }

    /**
     * 获取折扣记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:discount:query')")
    @GetMapping(value = "/{discountId}")
    public AjaxResult getInfo(@PathVariable("discountId") Long discountId)
    {
        return success(sysDiscountService.selectSysDiscountByDiscountId(discountId));
    }

    /**
     * 新增折扣记录
     */
    @PreAuthorize("@ss.hasPermi('system:discount:add')")
    @Log(title = "折扣记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysDiscount sysDiscount)
    {
        return toAjax(sysDiscountService.insertSysDiscount(sysDiscount));
    }

    /**
     * 修改折扣记录
     */
    @PreAuthorize("@ss.hasPermi('system:discount:edit')")
    @Log(title = "折扣记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysDiscount sysDiscount)
    {
        return toAjax(sysDiscountService.updateSysDiscount(sysDiscount));
    }

    /**
     * 删除折扣记录
     */
    @PreAuthorize("@ss.hasPermi('system:discount:remove')")
    @Log(title = "折扣记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{discountIds}")
    public AjaxResult remove(@PathVariable Long[] discountIds)
    {
        return toAjax(sysDiscountService.deleteSysDiscountByDiscountIds(discountIds));
    }
}
